/**
 * 
 */
package com.app.commons.exceltool;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.apache.log4j.Logger;



/**
 * @author yuxk
 *
 */
public class ExcelTool {

	/**
	 * 
	 */
	public ExcelTool() {
		logger.info(this.getClass().getName()+" loader");
	}
	
	private static Logger logger = Logger.getLogger(ExcelTool.class);
	
	/**
	 * key:具体excel模板名
	 * value:具体的excel地址
	 */
	private Map<String,String> excelpool = new HashMap<String,String>();
	
	private Map<String,byte[]> exceroot = new HashMap<String,byte[]>();
	
	public void init()
	{
		logger.info("模板文件加载开始！");
		Set<String> keys = this.excelpool.keySet();
		String path  = "";
		for(String key:keys)
		{
			try {
				path= this.getClass().getResource(this.excelpool.get(key)).getFile();
				FileInputStream input = new FileInputStream(path);
				byte[] b = new byte[input.available()];
				input.read(b);
				input.close();
				this.exceroot.put(key, b);
				
			} catch (FileNotFoundException e) {
				logger.error(e);
				logger.info(key+":模板文件加载失败");
			} catch (IOException e) {
				logger.info(key+":模板文件加载失败");
			}
		}
		logger.info("模板文件加载完成");
	}
	
	public byte[] getExcel(String key)
	{
		return this.exceroot.get(key);
	}
	
	
	
	public Map<String, String> getExcelpool() {
		return excelpool;
	}



	public void setExcelpool(Map<String, String> excelpool) {
		this.excelpool = excelpool;
	}


}
